import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;


public class WebListener {

	public static void main(String[] args) throws IOException {
		List<String> URL_list= new ArrayList<String>();
		 ServerSocket serverSocket = new ServerSocket(9000);
	
		 while (true) 
		 {
			 System.out.println("waiting for connection at 9000");
			 
			 Socket s = serverSocket.accept();
			 System.out.println("connection established from " + s.getInetAddress());
			 //System.out.println(s.getPort()); remote port number of the client
			 System.out.println("Connection Definition " + s.toString());
			 
			 BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			 String input = br.readLine();
			 
			 // keep repeating until an empty line is read.
			 while (input.compareTo("") != 0) {
				
				 URL_list.add(input);
				 System.out.println(input);
				 //output.writeBytes(input.toUpperCase() + "\n");
				try{
				 input = br.readLine();
				}
				catch (IOException e) {
				System.out.println(e.getMessage());
				s.close();
				return;
				}
			}
			// close current connection
			s.close();
		 }

	}

}
